package com.app.ui.adapter.mood;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.app.net.res.mood.Mood;
import com.app.ui.activity.mood.MoodDetailsActivity;
import com.app.ui.adapter.base.AbstractBaseAdapter;
import com.app.utiles.other.ActivityUtile;
import com.app.utiles.time.DateUtile;
import com.wxj.zx.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 郭敏 on 2018/1/25 0025.
 */

public class MoodAdapter extends AbstractBaseAdapter<Mood> {
    @Override
    protected View createView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_mood, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        Mood mood = list.get(i);
        viewHolder.moodTimeTv.setText(DateUtile.getDateFormat(mood.moodTime, DateUtile.DATA_FORMAT_YMD));
        viewHolder.moodMsgTv.setText(mood.moodMsg);
        view.setOnClickListener(new Click(i));
        return view;
    }

    class ViewHolder {
        @Bind(R.id.mood_time_tv)
        TextView moodTimeTv;
        @Bind(R.id.mood_msg_tv)
        TextView moodMsgTv;
        @Bind(R.id.line_view)
        View lineView;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    @Override
    protected void onViewClick(int index, int viewId) {
        Mood mood = list.get(index);
        ActivityUtile.startActivitySerializable(MoodDetailsActivity.class, mood);
    }
}
